define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'team/index',
                    add_url: 'user/user/add',
                    // edit_url: 'user/user/edit',
                    del_url: 'user/user/del',
                    multi_url: 'user/user/multi',
                    table: 'user',
                }
            });

            var table = $("#table");

            //当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                console.log(data);
                //这里我们手动设置底部的值
                $("#money").text(data.extend.money);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'user.id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
                        // {field: 'avatar', title: __('Avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'revenue', title: __('提成总收益'), operate: false},
                        // {field: 'record', title: __('Record'),table: table,
                        //     buttons: [{
                        //         name: 'Record',text: "消费记录",title: "消费记录",classname: 'btn btn-xs btn-primary btn-dialog',url:'user/userconsume/index'
                        //     }],
                        //     formatter: function (value,row,index){
                        //         var that = $.extend({}, this);
                        //         var table = $(that.table).clone(true);
                        //         $(table).data("operate-edit", null);
                        //         $(table).data("operate-del", null);
                        //         that.table = table;
                        //         return Table.api.formatter.operate.call(that, value, row, index);
                        //     },
                        //     events:Table.api.events.operate,operate:false
                        // },
                        {
                            field: 'record',
                            // width: "150px",
                            title: __('提成记录'),
                            table: table,
                            events: Table.api.events.operate,
                            operate: false,
                            buttons: [
                                {
                                    name: 'record',
                                    text: "提成记录",
                                    title: '提成记录',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'user/user/record',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    }
                                },
                            ],
                            formatter: Table.api.formatter.operate
                        },
                        {
                            field: 'record',
                            // width: "150px",
                            title: __('消费记录'),
                            table: table,
                            events: Table.api.events.operate,
                            operate: false,
                            buttons: [
                                {
                                    name: 'record',
                                    text: "消费记录",
                                    title: '消费记录',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'user/user/recordMoney',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                },
                            ],
                            formatter: Table.api.formatter.operate
                        },
                        {
                            field: 'record',
                            // width: "150px",
                            title: __('爱心值记录'),
                            table: table,
                            events: Table.api.events.operate,
                            operate: false,
                            buttons: [
                                {
                                    name: 'record',
                                    text: "爱心值记录",
                                    title: '爱心值记录',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'user/user/recordInt',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    }
                                },
                            ],
                            formatter: Table.api.formatter.operate
                        },
                        {
                            field: 'team',
                            // width: "150px",
                            title: __('Team'),
                            table: table,
                            events: Table.api.events.operate,
                            operate: false,
                            buttons: [
                                {
                                    name: 'team',
                                    text: "我的团队",
                                    title: '我的团队',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'team/index/team',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    }
                                },
                            ],
                            formatter: Table.api.formatter.operate
                        },
                        {field: 'create_time', title: '创建时间', operate: 'LIKE', addclass: 'datetimerange'},
                        // {field: 'create_time', title: __('创建时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

            // {field: 'team', title: __('Team'),table: table,
                        //     buttons: [{
                        //         name: 'team',text: "我的团队",title: "我的团队",classname: 'btn btn-xs btn-primary btn-dialog',url:'user/user/record'
                        //     }],
                        //     formatter: function (value,row,index){
                        //         var that = $.extend({}, this);
                        //         var table = $(that.table).clone(true);
                        //         $(table).data("operate-edit", null);
                        //         $(table).data("operate-del", null);
                        //         that.table = table;
                        //         return Table.api.formatter.operate.call(that, value, row, index);
                        //     },
                        //     events:Table.api.events.operate,operate:false
                        // },

                        // {field: 'status', title: __('Status'), searchList: {"1":__('No'),"2":__('Yes')}, formatter: Table.api.formatter.toggle},
                        // {field: 'successions', title: __('Successions'), visible: false, operate: 'BETWEEN', sortable: true},
                        // {field: 'maxsuccessions', title: __('Maxsuccessions'), visible: false, operate: 'BETWEEN', sortable: true},
                        // {field: 'logintime', title: __('Logintime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        // {field: 'loginip', title: __('Loginip'), formatter: Table.api.formatter.search},
                        // {field: 'jointime', title: __('Jointime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        // {field: 'joinip', title: __('Joinip'), formatter: Table.api.formatter.search},
                        // {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {normal: __('Normal'), hidden: __('Hidden')}},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});